<?php
/**
 * Created by PhpStorm.
 * User: M_Calven
 * Date: 2018/4/27
 * Time: 11:27
 */

namespace common\service;


class FilterFieldService
{

    /**
     * 过滤算法
     * @param mixed $context
     * @return array
     */
    public static function filter($context)
    {
        if (! is_array($context)) {
            return $context;
        }
        $filterFieldsStr = UtilService::getSystemParamByKey('log_filter_field');
        $filterFields = explode(',', $filterFieldsStr);
        $filterFields = array_map(function ($row) {
            return strtolower($row);
        }, $filterFields);

        foreach ($context as $key => $item) {
            if (in_array(strtolower($key), $filterFields)) {
                $context[$key] = '********';
            } elseif (is_array($item)) {
                $context[$key] = self::filter($item);
            }
        }
        return $context;
    }
}